const {
  request
} = require("utils/index.js")
App({
  onLaunch: function () {
    // 隐藏系统tabbar
    //wx.hideTabBar();
    this.getSystemInfo();
    // 获取设备信息
    //  this.getSystemInfo();
    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    var _token = wx.getStorageSync('token');
    var _this = this;
  },
  
  onShow: function () {
    //隐藏系统tabbar
    // wx.hideTabBar();
  },
  getSystemInfo: function () {
    let t = this;
    wx.getSystemInfo({
      success: function (res) {
        t.globalData.systemInfo = res;
      }
    });
  },
  editTabbar: function () {
    let tabbar = this.globalData.tabBar;
    let currentPages = getCurrentPages();
    let _this = currentPages[currentPages.length - 1];
    let pagePath = _this.route;
    // if(pagePath.indexOf('/') != 0) {
    //   pagePath = '/' + pagePath
    // }
    // (pagePath.indexOf('/') != 0) && (pagePath = '/' + pagePath);
    for (let i in tabbar.list) {
      tabbar.list[i].selected = false;
      if (tabbar.list[i].pagePath.indexOf(pagePath) != -1) {
        tabbar.list[i].selected = true
      }
      if (tabbar.list[i].pagePath.indexOf('/') != 0) {
        tabbar.list[i].pagePath = "/" + tabbar.list[i].pagePath;
      }
      if (tabbar.list[i].iconPath.indexOf('/') != 0) {
        tabbar.list[i].iconPath = "/" + tabbar.list[i].iconPath;
      }
      if (tabbar.list[i].selectedIconPath != undefined) {
        if (tabbar.list[i].selectedIconPath.indexOf('/') != 0) {
          tabbar.list[i].selectedIconPath = "/" + tabbar.list[i].selectedIconPath;
        }
      }
    }
    _this.setData({
      tabbar: tabbar
    });
  },
  globalData: {
    userInfo: null,
    tabBar: {
      "backgroundColor": "#ffffff",
      "color": "#979795",
      "selectedColor": "#388ef3",
      "list": [{
          "pagePath": "pages/home/home",
          "text": "首页",
          "iconPath": "icon/shouye.png",
          "selectedIconPath": "icon/shouyexuan.png"
        },
        {
          "pagePath": "icon/zu695.png",
          "iconPath": "icon/zu695.png",
          "isSpecial": true,
          "text": "发布"
        },
        {
          "pagePath": "pages/logs/logs",
          "text": "我的",
          "iconPath": "icon/wode.png",
          "selectedIconPath": "icon/wodexuan.png"
        }
      ]
    }
  }
})